#!/usr/bin/python

import unittest, re, os, sys
from nwgr import *


class Test1(unittest.TestCase):
	def setUp(self):
		print ''
	def testcf(self):
		self.assert_(re.compile(tk2frgx('cf')).search('lala.cpp') != None)
		self.assert_(re.compile(tk2frgx('cf')).search('lala.c') != None)
		self.assert_(re.compile(tk2frgx('cf')).search('lala.h') != None)
		self.assert_(re.compile(tk2frgx('cf')).search('lala.hh') != None)

	def testcs(self):
		self.assert_(re.compile(tk2frgx('cs')).search('lala.cpp') != None)
		self.assert_(re.compile(tk2frgx('cs')).search('lala.c') != None)
		self.assert_(re.compile(tk2frgx('cs')).search('lala.h') == None)
		self.assert_(re.compile(tk2frgx('cs')).search('lala.hh') == None)

	def testch(self):
		self.assert_(re.compile(tk2frgx('ch')).search('lala.cpp') == None)
		self.assert_(re.compile(tk2frgx('ch')).search('lala.c') == None)
		self.assert_(re.compile(tk2frgx('ch')).search('lala.h') != None)
		self.assert_(re.compile(tk2frgx('ch')).search('lala.hh') != None)


class TestTree(unittest.TestCase):
	def setUp(self):
		os.chdir("/tmp")
		os.system("rm -rf /tmp/trtt")
		os.mkdir("trtt")
		#except:
		print ''
		os.chdir("/tmp/trtt")
		file("a","w+b").write("abcde")
		file("b","w+b").write("abcde")
		file("c","w+b").write("abcde")
		os.mkdir("dd")
		os.chdir("dd")
		file("fd","w+b").write("abcde")
		file("gd","w+b").write("abcde")
	def testtreenr(self):
		a = walktree(["/tmp/trtt"], False)
		aa = []
		for i in a:
			aa.append(i[10:])
		print aa
		self.assert_("a" in aa)
		self.assert_("b" in aa)
		self.assert_("c" in aa)
		self.assert_("dd" not in aa)

		self.assert_("fd" not in aa)
		self.assert_("gd" not in aa)
		self.assert_(len(aa) == 3)
	def testtreer(self):
		a = walktree(["/tmp/trtt"], True)
		aa = []
		for i in a:
			aa.append(i[10:])
		print aa
		self.assert_("a" in aa)
		self.assert_("b" in aa)
		self.assert_("c" in aa)
		self.assert_("dd" not in aa)

		self.assert_("dd/fd" in aa)
		self.assert_("dd/gd" in aa)
		self.assert_(len(aa) == 5)

unittest.main()
